a = input()
if int(a) > 999 and int(a) < 10000:
    s1 = a[0]
    s2 = a[1]
    s3 = a[2]
    s4 = a[3]
    n = [int(s1),
         int(s2),
         int(s3),
         int(s4),
         int(s1+s2),
         int(s2+s3),
         int(s3+s4),
         int(s1+s2+s3),
         int(s2+s3+s4),
         int(s1+s2+s3+s4)]
    t = 0
    a2 = []
    for c in n:
        t = 0
        for d in range(2, c - 1):
            if c % d == 0:
                t = 1
        if t == 0:
            a2.append(c)
    if len(a2) > 0:
        print(max(a2))
    else:
        print(0)
else:
    print(0)
        
        



